﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Think.Lenovo.Com.Models.NewsModel;
using Think.Lenovo.Com.DataAccess.NewsInfo;
using Think.Lenovo.Com.Common;

namespace Think.Lenovo.Com.home
{
    public partial class userhome : System.Web.UI.Page
    {
        public String css1 = String.Empty;//最新资讯
        public String css2 = String.Empty;//最新政策及活动
        protected void Page_Load(object sender, EventArgs e)
        {
            #region//显示　最新资讯 或者 最新活动 
            String show = Request["show"];
            if (String.IsNullOrEmpty(show))
            {
                show = "1";
            }
            else if (show == "1")
            {
                show = "1";
            }
            else
            {
                show = "2";
            }
            #endregion

            try
            {
                int pageIndex = 1;
                int pageSize = 3;
                if (!Int32.TryParse(Request["pageIndex"], out pageIndex))
                {
                    pageIndex = 1;
                }
                String conditions = String.Empty;
                if (show == "1")
                {
                    conditions = " types=2 ";
                    css1 = "contright_title_a";
                    css2 = "contright_title_b";
                }
                else
                {
                    conditions = " types=3 ";
                    css1 = "contright_title_b";
                    css2 = "contright_title_a";
                }

                #region//Step1 得到 最新资讯
                NewsInfo news = new NewsInfo();
                LinkedList<NewsModel> list = news.GetViewNews(pageIndex, pageSize, conditions, "ReleaseDate desc");
                this.NewsList.DataSource = list;
                this.NewsList.DataBind();
                #endregion

                #region//Step 2 分页
                int recordCount = news.GetNewsCount(conditions);
                LinkedList<PageNumberModel> pages = PageBuilder.LinkedPage(recordCount, pageSize, pageIndex, 10, "userbook.aspx?pageIndex={pageIndex}", "{pageIndex}");
                this.Pages.DataSource = pages;
                this.Pages.DataBind();

                #endregion
            }
            catch (Exception ex)
            {
 
            }
        }
    }
}